{extend name="extend:iframe" /}

{block name="css"}
<link rel="stylesheet" type="text/css" href="/public/admin/css/layout.global.css" />
<style type="text/css">
.box {
    position: relative;
    float: left;
    width: 282px;
    height: 200px;
    margin: 15px;
    background-color: #50AF51;
    border-radius: 2px;
    background-image: url(/public/webfe/images/org_bg2.jpg);
}
.box img {
    display: block;
    width: 90px;
    height: 90px;
    margin: 15px auto;
}
.box ._org_title {
    color: #fff;
    text-align: center;
}
.box ._org_tools {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 10px;
    text-align: center;
}
.box ._org_tools i {
    font-size: 16px;
    color: #fff;
    margin-right: 1px;
}
.box ._org_tools a {
    font-size: 14px;
    color: #fff;
    margin: 0 6px;
}
</style>
{/block}


{block name="body"}
<div class="_title">
    <div class="_main">合作机构</div>
    <div class="_sub clearfix">
        <div class="_btns">
            <ul class="clearfix">
                <li class="active">机构列表</li>
                <li layout-mark="link" data-href="/admin/org/org.html">新增机构</li>
            </ul>
        </div>
    </div>
</div>
<div class="_content clearfix" id="agency-volist-view">
    
</div>
<div class="loadmore-modal">
	<a href="javascript:;">点击加载更多</a>
</div>
{/block}


{block name="js"}
<script type="text/html" id="agency-volist-template">
	{{# for ( var i in d ) { }} 
		{{# var list = d[i]; }}
		<div class="box" data-id="{{ list.id }}">
			<img src="{{ list.logo }}" />
			<p class="_org_title">{{ list.title }}</p>
			<p class="_org_tools b-line-t">
				<a href="/organization/{{ list.id }}.html" target="_blank"><i class="icon-to_view v-middle"></i>查看</a>
				<a href="/admin/org/org.html?orgid={{ list.id }}"><i class="icon-edit v-middle"></i>编辑</a>
				<a href="javascript:;" data-cmd="sc" data-id="{{ list.id }}"><i class="icon-delete v-middle"></i>删除</a>
			</p>
		</div>
	{{# } }}
</script>
<script type="text/javascript" src="/public/plug/layer/layer.min.js"></script>
<script type="text/javascript" src="/public/plug/laytpl/laytpl.min.js"></script>
<script type="text/javascript" src="/public/modules/tool.js"></script>
<script type="text/javascript" src="/public/modules/interactive.js"></script>
<script type="text/javascript">
	$(function() {
		// 页面跳转
		$('li[layout-mark=link]').on('click', function() {
			window.location.href = $(this).attr('data-href');
		});
		
		// 删除
		$('#agency-volist-view').on('click', 'a[data-cmd="sc"]', function() {
			var that = $(this),
				_id = that.attr('data-id'),
				data_opt = {
					'id': _id
				};
			layer.open({
				type: 0,
				title: '提示',
				content: '是否删除',
				btn: ['确定', '取消'],
				yes: function(index) {
					layer.load(0, {
						shade: [0.08, '#000']
					});
					ajax().del('/api?agency.admin.delete', data_opt, function(res) {
						layer.closeAll('loading');
						if(res.status == 204) {
							window.parent.system.success('删除成功', function() {
								$('div[data-id=' + _id + ']').remove();
							});
						} else {
							window.parent.system.error(res.error);
						}
					});
					layer.close(index);
				},
				btn2: function(index) {
					layer.close(index);
				}
			});
		});
		
		// 加载更多
		$('.loadmore-modal a').on('click', function(e) {
			var next = $(this).data('next');
			if(next > 0) {
				data_opt_volist['page'] = next;
				getActivityVolist();
			}
		});
	});
	
	var template = document.getElementById('agency-volist-template').innerHTML,
		data_opt_volist = dataOptVolist();
	
	// 加载列表
	function getAgencyVolist() {
		layer.load(0, {
			shade: [0.08, '#000']
		});
		ajax().get('/api?agency.admin.volist', data_opt_volist, function(res) {
			//console.dir(res);
			layer.closeAll('loading');
			if(res.status >= 200 && res.status < 300) {
				$('.loadmore-modal a').data('next', res.data.next);
				if(res.data.length > 0) {
					// 渲染列表
					var tpl = laytpl(template);
					$('#agency-volist-view').append(tpl.render(res.data));
					// 判断是否有分页
					if(res.data.next > res.data.page) {
						$('.loadmore-modal a').html('点击加载更多');
					} else {
						$('.loadmore-modal a').html('');
					}
				} else {
					$('.loadmore-modal a').html('暂无记录');
				}
			} else {
				window.parent.system.error(res.error);
			}
			// 重置页面高度
			resetIframeHeight();
		});
	}
	
	getAgencyVolist();
	
	function dataOptVolist(opts) {
		return tool.optionExtend({
			'page': 1, // 当前页数
			'show': 10 // 显示条数
		}, opts || {});
	}
</script>

{/block}